package com.caojing.syby.ui.cart.cartsharefragment;

import android.os.Handler;
import android.os.Looper;

import com.caojing.syby.bean.home.RowsBean;
import com.caojing.syby.bean.tenbuy.ShareGvBean;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/10/7 0007.
 */
public class CarfragmentSharePresenter implements CarfragmentShareConstract.Presenter{
    private CarfragmentShareConstract.View view;
    private CarfragmentShareConstract.Modle modle;


    public CarfragmentSharePresenter(CarfragmentShareConstract.View view){
        this.view=view;
        this.modle=new CarfragmentShareModle();
    }



    @Override
    public void getVertical(Map<String, String> params) {
        modle.getVertical(params, new Callback<ShareGvBean>() {
            @Override
            public void onResponse(Call<ShareGvBean> call, Response<ShareGvBean> response) {
                ShareGvBean shareGvBean = response.body();
                final List<RowsBean> rows = shareGvBean.getRows();
                Handler handler=new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVerticalSucess(rows);
                    }
                });
            }

            @Override
            public void onFailure(Call<ShareGvBean> call, Throwable t) {
                Handler handler=new Handler((Looper.getMainLooper()));
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVerticalFail("网络连接失败");
                    }
                });
            }
        });



    }
}
